

//--------------------------------------------------------------------------------------------------------------------
// this variable is used when creating the pick list where we choose the asset to delete.
// when it is 1 it will alert that the suppression of the asset has been successfuly performed.
// This message make no sense when not called after the suppression of an asset
globalSuppressedAssetName = "";
doSel2 = true;

//--------------------------------------------------------------------------------------------------------------------
// function which actually kills the asset
function killAssetImpl(functionToCall, betroomName) 
{   
    var sel1 = document.getElementById('assetToKillDropList');
    // If the post method is successful, we are going regenerate the asset pick list (because one has disapeared)
    // and we will display a success message there.  please note than on "error" this variable is set to "" again
    globalSuppressedAssetName = sel1.value;
    return submitWithReload(
        functionToCall,
        { 'assetToKillName' : globalSuppressedAssetName, 'betroom':betroomName },
        globalSuppressedAssetName + ' succesfully deleted'
        ); 
};

//--------------------------------------------------------------------------------------------------------------------
// this function asks for confirmaton from the user, saves the base and calls the function which actually kills the asset
function killAsset( functionToCall, betroomName ) 
{
	var test1 = confirm('This action cannot be manually reverted. Before doing it, the base will be saved but in case of problem you will have to re create the data base from saved files losing all not functional information. Do you want to continue?');
	if( test1 )
	{
	    var test2 = confirm('Are you realy sure? Maybe you should check ./savedRoomFiles because you are about to save the base. Do you want to continue?');
	    if( test2 )
	    {
	        ap_showWaitMessage(true, '' );
	        // save the base and calls the actual function
	        var args = { 
               type: "POST", 
               url: "/admin2/saveRoom/",
               cache: false,
               complete:function()  { killAssetImpl(functionToCall, betroomName); } ,
               error: function(errorThrown)  { document.write(errorThrown.responseText);  }
            };
            $.ajax(args);
	    }
	}
	return false;
};

//--------------------------------------------------------------------------------------------------------------------
// this function registers the function to call to the asset in the shame mode
function killAssetMtM(betroomName) 
{   
    // register the function to call later
	killAsset("/admin2/killAssetMtM/", betroomName);
};
//--------------------------------------------------------------------------------------------------------------------
// this function registers the function to call to the asset in the glory mode
function killAssetNumbers(betroomName) 
{
    // register the function to call later
	killAsset("/admin2/killAssetNumbers/", betroomName);
};
//--------------------------------------------------------------------------------------------------------------------
// this function registers the function to call to the asset in the glory mode
function killAssetInGloryMode() 
{
    // register the function to call later
	killAsset("/killAssetInGloryMode/","");
};


//--------------------------------------------------------------------------------------------------------------------
// this function fills the pick list with the asset from the data base
function fillAssetPickList(assetListRep)
{
    var allJsonsList = eval( assetListRep.responseText );
    assetList = allJsonsList[0].assets
    // create reference to first select
    sel1 = document.getElementById('assetToKillDropList');
    if( doSel2 )
    {
        sel2 = document.getElementById('payingAssetDropList');
    }
    
    //get the total item from the dropDownList   
    var intTotalItems = sel1.options.length;
    //loop through the number of items and remove them
    for(var intCounter=intTotalItems;intCounter>=0;intCounter--)
    {
        sel1.remove(intCounter);
        if( doSel2 )
        {
            sel2.remove(intCounter);
        }
    }

    // create the text which indicate what do the option
    sel1.options[sel1.length++] = new Option("Pick up asset", "Pick up asset");
    if( doSel2 )
    {
        sel2.options[sel2.length++] = new Option("Pick up paying asset", "Pick up paying asset");
    }
    

    // fill the first dropdown uninvested stategies
     for (var i = 0; i < assetList.length; i++)
     {
        var assetName = assetList[i].assetName;
        sel1.options[sel1.length++] = new Option( assetName, assetName );
        if( doSel2 )
        {
            sel2.options[sel2.length++] = new Option( assetName, assetName );
        }
     }
};



//--------------------------------------------------------------------------------------------------------------------
// this function asks for the list of the assets and call the function wich creates the pic list
function fillAssetToKillPickListRequest(doSel2Caller,betroomName)
{
    doSel2 = doSel2Caller;
    // we now have to update the status so that we will not get the message next time we get here except if this globalSuppressedAssetName has been set to 1 again
    globalSuppressedAssetName = "";
    var args = { 
           type: "POST", 
           url: "/json/getSpecificJson/",
           cache: false,
           data: { 'includeNonStd' : doSel2, 'func' :'getAssets', 'betroom':betroomName }, 
           complete:function(res)  { 
                        fillAssetPickList(res);
                        if( globalSuppressedAssetName != '' )
                        {
                            alert( globalSuppressedAssetName + " successfully supressed from database" );
                        }
                    },
           error: function(errorThrown)  { document.write(errorThrown.responseText);  }
           };
    $.ajax(args);
    return false;  
};